package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @program: tanhua
 * @description:
 * @author: MR.peng
 * @create: 2022-03-13 22:22
 **/

@RestController
@RequestMapping("/comments")
public class CommentsController {

    @Autowired
    private CommentsService commentsService;

    /*
    * 查询评论列表
    * 接口路径:GET
    * 参数：
    *   movementId,page,pageSize
    *  返回值：
    *   PageResult ----List<CommentVo>
    *
    * */

    @GetMapping
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pageSize,
                                   String movementId){
        PageResult vo = commentsService.findComments(movementId,page,pageSize);
        return ResponseEntity.ok(vo);
    }

    /*
    * 发布评论
    *   接口路径：POST
    *   参数  Body:
    *       movementId,comment(评论内容)
    *   返回值:
    *       void
    * */
    @PostMapping
    public ResponseEntity saveComment(@RequestBody Map map){
        //1.获取参数
        String movementId = (String) map.get("movementId");
        String comment = map.get("comment").toString();
        //2.调用service
        commentsService.saveComment(movementId,comment);

        //3.返回
        return ResponseEntity.ok(null);
    }
}
